" __  __         _   _                 _           
"|  \/  |_   _  | \ | | ___  _____   _(_)_ __ ___  
"| |\/| | | | | |  \| |/ _ \/ _ \ \ / / | '_ ` _ \ 
"| |  | | |_| | | |\  |  __/ (_) \ V /| | | | | | |
"|_|  |_|\__, | |_| \_|\___|\___/ \_/ |_|_| |_| |_|
"        |___/                                     
" Author: @TheIce-Star
" Github: @https://github.com/TheIce-Star/nvim
" GItee: @https://github.com/TheIcestar/nvim
" ThinkYou: ThinkVim and Neovim
if &compatible
	" vint: -ProhibitSetNoCompatible
	set nocompatible
	" vint: +ProhibitSetNoCompatible
endif


" Set main configuration directory as parent directory
let $VIM_PATH = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
let $THINKVIM = expand($HOME.'/.GoodVim.d/')

" set the user config file
let s:user_init_config = expand($THINKVIM.'/init.vim')

" Disable vim distribution plugins
let g:loaded_gzip = 1
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
let g:loaded_zip = 1
let g:loaded_zipPlugin = 1

let g:loaded_getscript = 1
let g:loaded_getscriptPlugin = 1
let g:loaded_vimball = 1
let g:loaded_vimballPlugin = 1

let g:loaded_matchit = 1
let g:loaded_matchparen = 1
let g:loaded_2html_plugin = 1
let g:loaded_logiPat = 1
let g:loaded_rrhelper = 1

let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                   source config                       "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                   I don't know                        "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

call utils#source_file($VIM_PATH,'core/packman.vim')
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                   vim seting                          "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

call utils#source_file($VIM_PATH,'core/general.vim')
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                   filetype                            "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

call utils#source_file($VIM_PATH,'core/filetype.vim')
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                   User Confg                          "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

source ~/.config/nvim/config/config.vim "this is your user config

" disable all keymaps of plugins
let g:thinkvim_disable_mappings = 0
" disable some plugins keymap
let g:thinkvim_disable_pmaping = []






















""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                     plug list            "
"                                 Vim Plug list            "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let s:dein_path = '~/.cache/dein'

" Add the dein installation directory into runtimepath
let &runtimepath = &runtimepath.','.s:dein_path.'/repos/github.com/Shougo/dein.vim'

if dein#load_state(s:dein_path)
  call dein#begin(s:dein_path, '~/.config/nvim/core/plugin.yaml')
  call dein#add(s:dein_path.'/repos/github.com/Shougo/dein.vim')
	call dein#add('theniceboy/vim-deus')
	call dein#add('liuchengxu/eleline.vim')
	call dein#add('wsdjeg/dein-ui.vim')
	call dein#add('junegunn/fzf')
  call dein#end()
  call dein#save_state()
endif

call plug#begin('~/.config/nvim/plugged/')
" Beautiful Plug
"Markdown
Plug 'dhruvasagar/vim-table-mode', {'for': ['markdown', 'vim-plug'],'on': ['TableModeToggle']}
"Automatic Completion
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Code Snippets
Plug 'honza/vim-snippets'
" File search
" File Tree
Plug 'ryanoasis/vim-devicons'
" Function
Plug 'Yggdroot/LeaderF', { 'do': './install.sh' }
" Cpp
Plug 'octol/vim-cpp-enhanced-highlight', {'for': ['cpp', 'vim-plug']}  " C++ syntax
" Python
Plug 'Vimjas/vim-python-pep8-indent', {'for': ['python', 'vim-plug']}
Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins', 'for' :['python', 'vim-plug'] }  " Python syntax
"little Plug in
Plug 'luochen1990/rainbow'
" tools
"Plug 'kevinhwang91/rnvimr' " rnager for (neo)vim


call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                                     Edit setting         "
"                                 Vim Edit setting         "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"======
"====== Deus theme
"======
colorscheme deus
set background=dark
set guifont=Source\ Code\ Pro:h12
hi Normal     ctermbg=NONE guibg=NONE
hi LineNr     ctermbg=NONE guibg=NONE
hi SignColumn ctermbg=NONE guibg=NONE
"======
"====== status line
"======
" eleline status line  to config
function! Buf_total_num()
return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
function! File_size(f)
let l:size = getfsize(expand(a:f))
if l:size == 0 || l:size == -1 || l:size == -2
return ''
endif
if l:size < 1024
return l:size.' bytes'
elseif l:size < 1024*1024
return printf('%.1f', l:size/1024.0).'k'
elseif l:size < 1024*1024*1024
return printf('%.1f', l:size/1024.0/1024.0) . 'm'
else
return printf('%.1f', l:size/1024.0/1024.0/1024.0) . 'g'
endif
endfunction
set statusline=%<%1*[B-%n]%*
" TOT is an abbreviation for total
set statusline+=%2*[TOT:%{Buf_total_num()}]%*
set statusline+=%3*\ %{File_size(@%)}\ %*
set statusline+=%4*\ %F\ %*
set statusline+=%5*『\ %{exists('g:loaded_ale')?ALEGetStatusLine():''}』%{exists('g:loaded_fugitive')?fugitive#statusline():''}%*
set statusline+=%6*\ %m%r%y\ %*
set statusline+=%=%7*\ %{&ff}\ \|\ %{\"\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"\ \|\"}\ %-14.(%l:%c%V%)%*
set statusline+=%8*\ %P\ %*
" default bg for statusline is 236 in space-vim-dark
hi User1 cterm=bold ctermfg=232 ctermbg=179
hi User2 cterm=None ctermfg=214 ctermbg=242
hi User3 cterm=None ctermfg=251 ctermbg=240
hi User4 cterm=bold ctermfg=169 ctermbg=239
hi User5 cterm=None ctermfg=208 ctermbg=238
hi User6 cterm=None ctermfg=246 ctermbg=237
hi User7 cterm=None ctermfg=250 ctermbg=238
hi User8 cterm=None ctermfg=249 ctermbg=240

"======
"====== vim-instant-markdown
"======
let g:instant_markdown_slow=0
let g:instant_markdown_autostart=0


"======
"====== Vim-table-made
"======
" set in noremal tm open vim-table-mode
map tm :TableModeToggle
"======
"====== coc.nvim
"======
" coc plug in
let g:coc_global_extensions = [
\ 'coc-css',
\ 'coc-html',
\ 'coc-json',
\ 'coc-python',
\ 'coc-vimlsp',
\ 'coc-explorer',
\ 'coc-git',
\ 'coc-diagnostic',
\ 'coc-snippets',
\ 'coc-translator',
\ 'coc-todolist',
\ 'coc-bookmark',
\ 'coc-calc',
\ 'coc-marketplace',]


" coc-config
"set hidden
" swop exit
set nobackup
set nowritebackup
set cmdheight=2
set shortmess+=c
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"  "open tab
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1]  =~# '\s'
endfunction

inoremap <silent><expr> <c-space> coc#refresh()

" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> <SPACE>- <Plug>(coc-diagnostic-prev)
nmap <silent> <SPACE>= <Plug>(coc-diagnostic-next)

" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> <SPACE>p :call <SID>show_documentation()<CR>
" Highlight the symbol and its references when holding the cursor.
"autocmd CursorHold * silent call CocActionAsync('highlight')


" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code.
exec "command! -nargs=0 Prettier"
xmap <space>f  <Plug>(coc-format-selected)
nmap <space>f  <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <SPACE>a  <Plug>(coc-codeaction-selected)
nmap <SPACE>a  <Plug>(coc-codeaction-selected)


function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction


"coc-snippet
imap <C-l> <Plug>(coc-snippets-expand)
vmap <C-j> <Plug>(coc-snippets-select)
let g:coc_snippet_next = '<C-j>'
let g:coc_snippet_prev = '<C-k>'
imap <C-j> <Plug>(coc-snippets-expand-jump)
let g:snips_author = 'TheIce-Star'


"coc-plugin key
"coc-prettier
nmap for :CocCommand prettier.formatFile<CR>
vmap for :CocCommand prettier.formatFile<CR>
vmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)
" coc-translator
nmap tt <Plug>(coc-translator-p)
vmap tt <Plug>(coc-translator-pv)
" coc-explorer
nmap ff :CocCommand explorer<CR>
" coc-calc
nmap <SPACE>ca <Plug>(coc-calc-result-append) " Calculation result is in later
nmap <SPACE>ca <Plug>(coc-calc-result-append) " Calculation result is in later
nmap <SPACE>cr <Plug>(coc-calc-result-replace) " Calculation result is replace
" coc-marketplace
nmap <LEADER>ww :CocList marketplace<CR>
" coc-bookmarks key
nmap bb <plug>(coc-bookmark-toggle)
nmap ba <plug>(coc-bookmark-annotate)
nmap bl :CocList bookmark<CR>
nmap bct :CocCommand bookmark.clearForCurrentFile<CR>
nmap bfo :CocCommand bookmark.clearForAllFiles<CR>
"coc-todolist key
nmap tn :CocCommand todolist.create<CR>
nmap tc :CocCommand todolist.clear<CR>
" ===
" === asyncrun
" ===
let g:asyncrun_open=6
nmap <C-S> :AsyncRun 
" ===
" === rainbow
" ===
let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle
let g:rainbow_conf = {
	\	'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
	\	'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
	\	'operators': '_,_',
	\	'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
	\	'separately': {
	\		'*': {},
	\		'tex': {
	\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
	\		},
	\		'lisp': {
	\			'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
	\		},
	\		'vim': {
	\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
	\		},
	\		'html': {
	\			'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
	\		},
	\		'css': 0,
	\	}
	\}

